package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.CommodityDao;
import com.dao.EmployeeDao;
import com.pojo.Commodity;
import com.pojo.Employee;

@Service("CommodityService")
public class CommmodityImpl implements CommodityService {

	@Autowired
	private CommodityDao commodityDao;
	@Autowired
	private EmployeeDao employeeDao;
	@Override
	public boolean addCommodity(Commodity commodity) {
		// TODO Auto-generated method stub
		boolean result;
		if (commodityDao.addCommodity(commodity) > 0)
			result = true;
		else
			result = false;
		return result;
	}

	@Override
	public boolean deletCommodityForId(Integer commodity_id) {
		// TODO Auto-generated method stub
		boolean result;
		if (commodityDao.deleteCommodityForId(commodity_id) > 0)
			result = true;
		else
			result = false;
		return result;
	}

	@Override
	public Commodity GetCommodity(Integer commodity_id) {
		// TODO Auto-generated method stub
		return commodityDao.selectCommodityForId(commodity_id);
	}

	@Override
	public List<Commodity> GetAllCommodity() {
		// TODO Auto-generated method stub
		return commodityDao.selectAllCommodity();
	}

	@Override
	public boolean updateCommodity(Commodity commodity) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		boolean result;
		if (commodityDao.deleteCommodityForId(commodity.getCommodity_Id()) > 0&&commodityDao.addCommodity(commodity)>0)
			result = true;
		else
			result = false;
		return result;
	}

	@Override
	public Employee GetEmployee(Integer employee_id) {
		// TODO Auto-generated method stub
		return employeeDao.selectEmployeeForId(employee_id);
	}

}
